﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SLCommon;

namespace SLHUDSystem
{
    public class HUDGroup 
    {
        public int Index;
        private HUDItem[] m_HUDItems;    
        private List<int> m_DirtyItemIndexes = new List<int>();
        private int m_ItemIndex = 0;

        public void CreateHUDItems(HUDItemType[] itemTypes)
        {
            m_HUDItems = new HUDItem[itemTypes.Length];
            for (int i = 0; i < m_HUDItems.Length; i++)
            {
                var item = HUDUtils.CreateHUDItem(itemTypes[i]);
                item.Index = i;
                item.OnDirtyChanged = OnItemDirty;
                m_HUDItems[i] = item;
            }
        }

        private void OnItemDirty(int itemIndex)
        {
            m_DirtyItemIndexes.Add(itemIndex);
        }

        public void UpdateGroup()
        {
            if (m_DirtyItemIndexes.Count >0)
            {
                for (int i = 0; i < m_DirtyItemIndexes.Count; i++)
                {
                    m_HUDItems[m_DirtyItemIndexes[i]].UpdateHUDItem();
                }
            }
        }
    }
}
